#include "Message.h"



Message::Message()
{

}

Message::Message(unsigned char *buffer)
{
	int messageLength = 0;
	messageLength |= buffer[0] << 24;
	messageLength |= buffer[1] << 16;
	messageLength |= buffer[2] << 8;
	messageLength |= buffer[3];

	this->header.SetMessageLength(messageLength);
	this->header.SetMessageType(static_cast<MessageType::MessageType>((int)(buffer[4])));

	unsigned char *ptrMessag = buffer + 5;
	this->message = string(reinterpret_cast<const char *>(ptrMessag), this->header.GetMessageLength() - 5);

}

Message::Message(MessageHeader header, string message)
{
	this->header = header;
	this->message = message;
}

Message::~Message()
{

}

void Message::SetHeader(MessageHeader header)
{
	this->header = header;
}

void Message::SetMessage(string message)
{
	this->message = message;
}

MessageHeader Message::GetMessageHeader()
{
	return header;
}

string Message::GetMessageStr()
{
	return message;
}

string Message::GetMessageBuffer()
{
	string buffer = header.GetMessageHeaderBuffer();
	buffer = buffer.append(message);
	return buffer;
}
